package com.shuang.tree2;

import java.util.ArrayList;
import java.util.List;

public class PostorderTraversal {

    public List<Integer> postorderTraversal(TreeNode root) {
        //递归实现 后续遍历
        List<Integer> result = new ArrayList<Integer>();

        postorder(root, result);

        return result;
    }

    public void postorder(TreeNode root, List<Integer> result){
        if (root == null){
            return;
        }

        //后续遍历 左右中
        postorder(root.left, result);
        postorder(root.right, result);
        result.add(root.val);  //注意这条语句
    }
}
